<template>
  <view class="shopCar-container" v-if="shopCar.length!==0">
    <!--收货地址-->
    <address-bar></address-bar>
    <!--標題区域-->
    <view class="shopCar-title">
      <!--左边图标-->
      <uni-icons type = "shop" size = "18"></uni-icons>
      <!--右边文字-->
      <text class="shopCar-text">购物车</text>
    </view>
    <!--循环渲染购物車商品-->
    <uni-swipe-action>
      <block v-for="(product , i) in shopCar" :key="i">
        <!--滑动刪除條-->
        <uni-swipe-action-item :right-options="options" @click="deleteButtonClick(product)">
          <product-item :product="product" :showRadio="true" :showNumBox="true" @radio-change="radioChangeSolve" @numBox-change = "numBoxChangeSolve"></product-item>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
    
    <!--结算组件-->
    <settle-bar></settle-bar>
  </view>
  
  <!--啥都沒有時的情況-->
  <view class="empty-shopCar" v-else>
    <image src="/static/farm_shop_mall/shopCarNoneItemBackground.png" class="empty-photo"></image>
  </view>
</template>

<script>
  import badgeMix from '@/store/tabbar-badge.js'
  import {mapState, mapMutations} from 'vuex'
  export default {
    mixins : [badgeMix],
    
    computed:{
      ...mapState('shopCar', ['shopCar'])
    },
    onShow(){

    },
    data() {
      return {
        options:[{
          text:'刪除',
          style:{
            backgroundColor:'#C00000'
          }
        }]
        
      };
    },
    methods:{
      ...mapMutations('shopCar', ['updateProductState','updateProductCount','removeProductByID']),
      radioChangeSolve(e){
        this.updateProductState(e)
      },
      numBoxChangeSolve(e){
        this.updateProductCount(e)
      },
      deleteButtonClick(product){
        this.removeProductByID(product)
        
        
      }

    }
  }
</script>

<style lang="scss">
  .shopCar-container{
    padding-bottom: 50px;
  }
  .shopCar-title{
    height: 40px;
    display: flex;
    align-items: center;
    padding-left: 5px;
    border-bottom: 1px soild #EFEFEF;
    .shopCar-text{
      font-size: 14px;
      margin-left: 10px;
    }
  }
  .empty-shopCar{
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 150px ;
    height:100vh;
    .empty-photo{
      width: 120px;
      height: 120px;
    }
  }

</style>
